﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GestionEco;
using GestionCases;

namespace Ecosystème
{
    public partial class frmDetailCase : Form
    {
        private Terrain _terrain;
        public Terrain terrain
        {
            get { return _terrain; }
            set { _terrain = value; }
        }

        private ListEtreVivant _evCourant;
        public ListEtreVivant evCourant
        {
            get { return _evCourant; }
            set { _evCourant = value; }
        }
        public frmDetailCase()
        {
           InitializeComponent();
        }

        private void frmDetailCase_Load(object sender, EventArgs e)
        {
            if (_terrain != null)
            {
                lbType.Text = _terrain.getType();
                lbEauMax.Text = _terrain.getHumidite().ToString();
                lbEauRestante.Text = _terrain.getQteEau().ToString();
                Image im = null;
                Bitmap img = null;
                if (terrain.getType() == "Mer")
                {
                    im = System.Drawing.Image.FromFile(Application.StartupPath + @"\Content\mer.jpg");
                    img = new Bitmap(im, new System.Drawing.Size(pbTerrain.Width, pbTerrain.Height));
                }
                if (terrain.getType() == "Plaine")
                {
                    im = System.Drawing.Image.FromFile(Application.StartupPath + @"\Content\Plaine.jpg");
                    img = new Bitmap(im, new System.Drawing.Size(pbTerrain.Width, pbTerrain.Height));
                }
                if (terrain.getType() == "Forêt")
                {
                    im = System.Drawing.Image.FromFile(Application.StartupPath + @"\Content\Foret.jpg");
                    img = new Bitmap(im, new System.Drawing.Size(pbTerrain.Width, pbTerrain.Height));
                }
                if (terrain.getType() == "Montagne")
                {
                    im = System.Drawing.Image.FromFile(Application.StartupPath + @"\Content\Montagne.jpg");
                    img = new Bitmap(im, new System.Drawing.Size(pbTerrain.Width, pbTerrain.Height));
                }
                if (terrain.getType() == "Désert")
                {
                    im = System.Drawing.Image.FromFile(Application.StartupPath + @"\Content\Desert.jpg");
                    img = new Bitmap(im, new System.Drawing.Size(pbTerrain.Width, pbTerrain.Height));
                }
                if (img != null)
                    pbTerrain.Image = img;
            }
            Bitmap img2 = null;
            foreach (EtreVivant ev in _evCourant.getListEtre())
            {
                img2 = new Bitmap(ev.getImageEtre(), 25, 25);
                ImageConverter converter = new ImageConverter();
                dgvListeEtre.Rows.Add(ev.getNomEtre(), (byte[])converter.ConvertTo(img2, typeof(byte[])));
            }
        }

        private void dgvListeEtre_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            foreach (EtreVivant ev in _evCourant.getListEtre())
            {
                if (dgvListeEtre.Rows[e.RowIndex].Cells["Nom"].Value.ToString() == ev.getNomEtre())
                {    
                    lbAtt.Text = ev.getAttaque().ToString();
                    lbDeg.Text = ev.getDegat().ToString();
                    lbEsq.Text = ev.getEsquive().ToString();
                    lbFAct.Text = ev.getFaimActuelle().ToString();
                    lbFMax.Text = ev.getFaimMax().ToString();
                    lbPA.Text = ev.getPointsAction().ToString();
                    lbReg.Text = ev.getRegen().ToString();
                    lbSAct.Text = ev.getSoifActuelle().ToString();
                    lbSMax.Text = ev.getSoifMax().ToString();
                    lbVAct.Text = ev.getVieActuelle().ToString();
                    lbVMax.Text = ev.getVieMax().ToString();
                    lbVue.Text = ev.getVue().ToString();
                }
            }
        }

        
    }
}
